----------------------------
-- Simplistic Street
-- by Jammie Dodger
--
-- Project Started - October 20, 2009
-- Completion -None
----------------------------

local meta = FindMetaTable( "Entity" );

local DoorTypes =
{

	"func_door",
	"func_door_rotating",
	"prop_door_rotating"

}

local OwnableTypes =
{
	
	"func_door",
	"func_door_rotating",
	"prop_door_rotating",
	"prop_vehicle_jeep",
	"prop_vehicle_jeep_old",
	"prop_vehicle_airboat"

}

local UnPhysgunnable =
{
	
	"func_door",
	"func_door_rotating",
	"prop_door_rotating",
	"player",
	"func_breakable",
	"func_brush",
	"func_tracktrain",
	"func_physbox",
	"func_breakable_surf",
	"func_movelinear",
	"prop_vehicle_jeep",
	"prop_vehicle_jeep_old",
	"prop_dynamic",
	"func_monitor"
	
}

local UnToolgunable =
{
	
	"func_breakable",
	"func_brush",
	"func_tracktrain",
	"func_physbox",
	"func_breakable_surf",
	"func_movelinear",
	
}

local BannedModels =
{
	"models/Cranes/crane_frame.mdl",
	"models/props_c17/column02a.mdl",
	"models/props_canal/canal_bridge01.mdl",
	"models/props_canal/canal_bridge02.mdl",
	"models/props_canal/canal_bridge03a.mdl",
	"models/props_canal/canal_bridge03b.mdl",
	"models/props_canal/canal_bridge04.mdl",
	"models\props_c17\oildrum001_explosive.mdl",
	"models\props_junk\gascan001a.mdl",
	"models\props_junk\propanecanister001a.mdl",
	"models\props_explosive\explosive_butane_can.mdl",
	"models\props_explosive\explosive_butane_can02.mdl",
	"models\props_junk\propane_tank001a.mdl",
	"models\Advisorpod_crash\Advisor_Pod_crash.mdl",
	"models\Combine_Advisor_Pod\combine_advisor_pod.mdl",
	"models\advisorpod.mdl",
	"models\extras\info_speech.mdl",
	"models/props_hive/websackHalf_b.mdl",
	"models/props_fortifications/flak38.mdl",
	"models/magnusson_teleporter.mdl",
	"models/props_explosive/explosive_butane_can02.mdl",
	"models/props_explosive/explosive_butane_can.mdl",
	"models/props_hive/websackHalf_b.mdl",
	"models/props_fortifications/hedgehog_small1_snow.mdl",
	"models/props_hive/websackceiling04.mdl",
	"models/vehicle/helicopter.mdl",
	"models/props_outland/forklift_body.mdl",
	"models/props_outland/chandelier.mdl",
	"models/combine_wall.mdl",
	"models/ep1_combine_wall.mdl",
	"models/Advisorpod_crash/Advisor_Pod_crash.mdl",
	"models/Cliffs/bridge.mdl",
	"models/Cliffs/bridge02.mdl",
	"models/Cliffs/cliff01.mdl",
	"models/Cliffs/o5cliff01.mdl",
	"models/Cliffs/o5cliff02.mdl",
	"models/Cliffs/o5cliff04.mdl",
	"models/Cliffs/o5cliff05.mdl",
	"models/map12_building2/ciron.mdl",
	"models/props_vehicles/halftrack_us1snow.mdl",
	"models/props_vehicles/jeep_us.mdl",
	"models/props_vehicles/kubelwagen_snow.mdl",
	"models/props_vehicles/lcvp_open.mdl",
	"models/props_vehicles/sherman_tank.mdl",
	"models/props_vehicles/tiger_tank.mdl",
	"models/props_vehicles/lcvp_closed.mdl",
	"models/props_vehicles/sherman_tank_destroyed.mdl",
	"models/props_vehicles/sherman_tank_snow.mdl",
	"models/props_vehicles/tiger_tank_snow.mdl",
	"models/props_vehicles/tiger_tank_snow_wrecked1.mdl",
	"models/map12_building2/brushwood.mdl",
	"models/map1_bridge/bridgeDamageLeft.mdl",
	"models/mini_borealis/mini_borealis.mdl",
	"models/props_radiostation/radio_antenna01.mdl",
	"models/props_silo/rocket_low.mdl",
	"models/seesawBridge/bridge_static_exit.mdl",
	"models/seesawBridge/bridge_standin.mdl",
	"models/props_c17/oildrum001_explosive.mdl",
	"models/props_wasteland/cargo_container01.mdl",
	"models/props_wasteland/medbridge_base01.mdl",
	"models/props_phx/huge/tower.mdl",
	"models/props_c17/column02a.mdl"

}

function meta:CanToolgunThis()

	local class = self:GetClass();
	
	for k, v in pairs( UnToolgunable ) do
	
		if( v == class ) then
			return false;
		end
	
	end
	
	return true;	

end

function meta:CanPhysgun()

	local class = self:GetClass();
	
	for k, v in pairs( UnPhysgunnable ) do
	
		if( v == class ) then
			return false;
		end
	
	end
	
	return true;

end


function IsBannedModel( mdl )

	mdl = string.gsub( mdl, "/", "\\" );

	for k, v in pairs( BannedModels ) do

		if( v == string.gsub( mdl, "\\", "" ) ) then
			return true;
		end
	
	end
	
	return false;

end

function meta:IsBannedProp()

	if( IsBannedModel( self:GetModel() ) ) then return true; end
	
	return false;

end

function meta:IsOwnable()

	local class = self:GetClass();
	
	for k, v in pairs( OwnableTypes ) do
	
		if( v == class ) then return true; end
	
	end
	
	return false;

end

local ElevatorTable = {

Vector(-751.0000, -1459.0000, -140.0000),
Vector(-783.0000, -1459.0000, -140.0000),
Vector(-751.0000, -1459.0000, -14.4100),
Vector(-783.0000, -1459.0000, -14.4100),
Vector(-751.0000, -1459.0000, 124.0000),
Vector(-783.0000, -1459.0000, 124.0000),
Vector(-783.0000, -1459.0000, 252.0000),
Vector(-751.0000, -1459.0000, 252.0000),
Vector(-751.0000, -1459.0000, 380.0000),
Vector(-783.0000, -1459.0000, 380.0000)

}

function GM:InitPostEntity( )
	self.BaseClass:InitPostEntity()
	
	if string.lower(game.GetMap()) == "rp_downtown_v2" then
		for j,l in pairs(ElevatorTable) do
		local EntitiesNearby = ents.FindInSphere( l, 50 )
			for x,y in pairs(EntitiesNearby) do
				if y:IsDoor() then
					y:SetNWBool("Elevator", true)
				end
			end
		end	
	end
		
	for k,v in pairs(ents.GetAll()) do
		if v:IsDoor() then
			v.IsOpened = false
			v:HookOutput("OnOpen", "OpenorClosed", function() v.IsOpened = true end)
			v:HookOutput("OnClose", "OpenorClosed", function() v.IsOpened = false end)
			
			if v:IsCopOnly() then
				v:Fire( "lock" )
				v.IsLocked = true
			else
				v:Fire( "unlock" )
				v.IsLocked = false
				end
		end
	end
end

function GM:PhysgunPickup( ply, Ent )
	if ( Ent:GetClass() == "player" ) then
		if ply:IsSuperAdmin() then
			return true
		else
			return false
		end
	end

	if ( string.find( Ent:GetClass(), "npc_" ) or string.find( Ent:GetClass(), "prop_dynamic" ) or string.find( Ent:GetClass(), "func_" ) ) then
		if ( !ply:IsSuperAdmin() ) then
			return false
		end
	end
	
	if Ent:CanPhysgun() then return true end
	
	return self.BaseClass:PhysgunPickup( ply, Ent )
end
